package com.lmbx.shzh.service.impl;

import com.lmbx.shzh.constant.AppConstants;
import com.lmbx.shzh.domain.common.ResponseResult;
import com.lmbx.shzh.domain.model.PersonDO;
import com.lmbx.shzh.exception.BusinessException;
import com.lmbx.shzh.exception.ErrorCodeEnum;
import com.lmbx.shzh.mapper.PersonDutyMapper;
import com.lmbx.shzh.service.PersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Auther: wyl
 * @Date: 2021/5/12
 * @Description:
 */
@Service
@Slf4j
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonDutyMapper personDutyMapper;

    /**
     * 根据日期查询值班人员
     *
     * @param date  日期
     * @param vCode 地区编码
     */
    @Cacheable(value = AppConstants.PERSON_API, key = "#date+'-'+#vCode")
    @Override
    public ResponseResult selectDutyList(String date, String vCode) {
        if (!StringUtils.hasText(date)) {
            throw new BusinessException(ErrorCodeEnum.PARAM_NULL);
        }
        List<PersonDO> personList = personDutyMapper.selectDutyList(date, vCode);
        // TODO 返回前台需要的格式，应该在controller层编写，传输层使用dto，略

        return ResponseResult.success(personList);
    }
}
